package com.itheima.sercive.CheckItemServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Setmeal;
import com.itheima.sercive.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class SetmealServiceImpl implements SetmealService {
    @Autowired
    private SetmealMapper setmealMapper;

/**
 * 新增套餐
 * @param setmeal
 */
    @Transactional
    public void add(Setmeal setmeal) {
        setmealMapper.add(setmeal);
    }
/**
 * 修改套餐
 * @param setmeal
 */

    @Transactional
    public void edit(Setmeal setmeal) {
        setmealMapper.update(setmeal);
    }

/**
 * 通过id查询套餐
 * @param id
 * @return
 */
    public Setmeal findById(Integer id) {
        return setmealMapper.findById(id);
    }
    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        Page<Setmeal> page = setmealMapper.findByCondition(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }
    /**
     * 添加
     * @param
     * @param checkgroupIds
     */

    private void setSetmealAndCheckGroup(Integer setmealId, Integer[] checkgroupIds) {
        for (Integer groupId : checkgroupIds) {
            setmealMapper.addAssociation(setmealId, groupId);
        }
    }
}
